package cn.dongqihong.produceconsumption;

/**
 * 食客
 * Created by DongQihong on 2016/12/15.
 */
public class Dinner implements Runnable {
    private String name;
    private boolean flag = true;
    private Basket basket;

    /**
     * 创建食客
     *
     * @param name   食客名
     * @param basket 取包子的篮子
     */
    public Dinner(String name, Basket basket) {
        this.name = name;
        this.basket = basket;
    }

    /**
     * 吃包子
     *
     * @param bun
     */
    private void eat(Bun bun) {
        try {
            Thread.sleep(800);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        bun = null;
    }

    @Override
    public void run() {
        while (flag) {
            Bun bun = basket.out();
            eat(bun);
        }
    }

    /**
     * 停止吃
     */
    public void stopEat() {
        flag = false;
    }
}
